package com.pig.pcart.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.pig.pcart.mapper.CartMapper;
import com.pig.pcart.service.CartService;
import com.pig.pojo.Cart;
import com.pig.util.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {
    @Autowired
    private CartMapper cartMapper;

    @Override
    public List<Cart> findUserItems(Integer userId) {
        /*QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("userId",userId);
        return cartMapper.selectList(queryWrapper);*/
        List<Cart> cartList= cartMapper.selectItemsByUserId(userId);
        System.out.println(cartList.toString());
        return cartList;
    }

    @Override
    public void changeNum(Cart cart) {
        System.out.println("service");
        UpdateWrapper<Cart> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("cartId",cart.getCartId());
        Cart cart1=new Cart();
        cart1.setNum(cart.getNum());
       cartMapper.update(cart1, updateWrapper);

    }
}
